package ink.lovejinhu.leetcode;

import java.util.HashSet;

/**
 * @author jinhu
 * created 2021-08-13 10:52
 */
public class Solution_0824 {
    public String toGoatLatin(String sentence) {
        HashSet<Character> characters = new HashSet<>();
        characters.add('a');
        characters.add('e');
        characters.add('i');
        characters.add('o');
        characters.add('u');

        characters.add('A');
        characters.add('E');
        characters.add('I');
        characters.add('O');
        characters.add('U');
        String[] s = sentence.split(" ");
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < s.length; i++) {

            if (characters.contains(s[i].charAt(0))) {  //元音开头
                StringBuilder temp = new StringBuilder(s[i] + "ma");
                for (int j = 0; j < i + 1; j++) {
                    temp.append("a");
                }
                stringBuilder.append(temp).append(" ");
            } else {  //辅音
                String v0 = s[i].substring(0, 1);
                String v1 = s[i].substring(1, s[i].length());
                StringBuilder v3 = new StringBuilder(v1 + v0 + "ma");
                for (int j = 0; j < i + 1; j++) {
                    v3.append("a");
                }
                stringBuilder.append(v3).append(" ");
            }
        }
        String string = stringBuilder.toString();
        return string.substring(0, string.length() - 1);
    }
}
